package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizSalesApproval;
import com.ruoyi.system.service.IBizSalesApprovalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单审核Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/system/approval")
public class BizSalesApprovalController extends BaseController
{
    private String prefix = "system/approval";

    @Autowired
    private IBizSalesApprovalService bizSalesApprovalService;

    @RequiresPermissions("system:approval:view")
    @GetMapping()
    public String approval()
    {
        return prefix + "/approval";
    }

    /**
     * 查询销售订单审核列表
     */
    @RequiresPermissions("system:approval:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizSalesApproval bizSalesApproval)
    {
        startPage();
        List<BizSalesApproval> list = bizSalesApprovalService.selectBizSalesApprovalList(bizSalesApproval);
        return getDataTable(list);
    }

    /**
     * 导出销售订单审核列表
     */
    @RequiresPermissions("system:approval:export")
    @Log(title = "销售订单审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizSalesApproval bizSalesApproval)
    {
        List<BizSalesApproval> list = bizSalesApprovalService.selectBizSalesApprovalList(bizSalesApproval);
        ExcelUtil<BizSalesApproval> util = new ExcelUtil<BizSalesApproval>(BizSalesApproval.class);
        return util.exportExcel(list, "销售订单审核数据");
    }

    /**
     * 新增销售订单审核
     */
    @RequiresPermissions("system:approval:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售订单审核
     */
    @RequiresPermissions("system:approval:add")
    @Log(title = "销售订单审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizSalesApproval bizSalesApproval)
    {
        return toAjax(bizSalesApprovalService.insertBizSalesApproval(bizSalesApproval));
    }

    /**
     * 修改销售订单审核
     */
    @RequiresPermissions("system:approval:edit")
    @GetMapping("/edit/{approvalId}")
    public String edit(@PathVariable("approvalId") Long approvalId, ModelMap mmap)
    {
        BizSalesApproval bizSalesApproval = bizSalesApprovalService.selectBizSalesApprovalByApprovalId(approvalId);
        mmap.put("bizSalesApproval", bizSalesApproval);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售订单审核
     */
    @RequiresPermissions("system:approval:edit")
    @Log(title = "销售订单审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizSalesApproval bizSalesApproval)
    {
        return toAjax(bizSalesApprovalService.updateBizSalesApproval(bizSalesApproval));
    }

    /**
     * 删除销售订单审核
     */
    @RequiresPermissions("system:approval:remove")
    @Log(title = "销售订单审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizSalesApprovalService.deleteBizSalesApprovalByApprovalIds(ids));
    }
}
